package cn.com.zpark.servlet_config;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.servlet_config
 * @ClassName: ServletConfigDemo02
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  10:34
 */
public class ServletConfigDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取servletConfig对象
        ServletConfig servletConfig = getServletConfig();
        // 获取相应的内容

        // 获取初始化参数，根据初始化参数的名字获取
        String name = servletConfig.getInitParameter("name");
        String local = servletConfig.getInitParameter("local");
        System.out.println(name+"："+local);

        // 获取servletContext对象
        ServletContext servletContext = servletConfig.getServletContext();
        System.out.println(servletContext);

        // 获取servlet名字
        String servletName = servletConfig.getServletName();
        System.out.println(servletName);



    }
}
